package org.wisdom.security.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.wisdom.service.ICheckPreAuthorizeService;

/**
 * 接口api访问权限验证
 *
 * @author 张智研
 * @date 2022/09/01 11:06
 */
@Service("ps")
public class PermissionService {

    @SuppressWarnings("SpringJavaAutowiredFieldsWarningInspection")
    @Autowired(required = false)
    private ICheckPreAuthorizeService checkPreAuthorizeService;

    /**
     * 验证用户是否具备某权限
     *
     * @param permission
     *            权限字符串
     * @return 用户是否具备某权限
     */
    public boolean hasPermission(String permission) {
        if(this.checkPreAuthorizeService != null) {
            return this.checkPreAuthorizeService.hasPermission(permission);
        }else {
            return true;
        }
    }
}
